﻿module sort_tests
open Xunit
open FSharpChess
//simple SEE check
[<Fact>]
let test_history_index() = 
    Psn_tests.setup_pos1() 
    let mv = Funcs.gm.CreateMove(Standard, 0, 4, 36, 28, 0)
    let indx = Sort.history_index mv Funcs.gm
    let cond=(indx=228)
    let mess="index calculated " + indx.ToString()
    Assert.True(cond,mess)
[<Fact>]
let test_mvv_lva() = 
    Psn_tests.setup_pos1() 
    let mv = Funcs.gm.CreateMove(Standard, 0, 4, 36, 28, 0)
    let scr = Sort.mvv_lva mv Funcs.gm
    let cond=(scr=2)
    let mess="mvv_lva score calculated " + scr.ToString()
    Assert.True(cond,mess)
[<Fact>]
let test_capture_is_good() = 
    Psn_tests.setup_pos1() 
    let mv = Funcs.gm.CreateMove(Standard, 0, 4, 36, 28, 0)
    let res = Sort.capture_is_good mv Funcs.gm
    let cond=(res=true)
    let mess="capture_is_good calculated " + res.ToString()
    Assert.True(cond,mess)
[<Fact>]
let test_move_value_simple() = 
    Psn_tests.setup_pos1() 
    let mv = Funcs.gm.CreateMove(Standard, 0, 4, 36, 28, 0)
    let scr = Sort.move_value_simple mv Funcs.gm
    let cond=(scr=2)
    let mess="move_value_simple calculated " + scr.ToString()
    Assert.True(cond,mess)
[<Fact>]
let test_capture_value() = 
    Psn_tests.setup_pos1() 
    let mv = Funcs.gm.CreateMove(Standard, 0, 4, 36, 28, 0)
    let scr = Sort.capture_value mv Funcs.gm
    let cond=(scr=4002)
    let mess="capture_value calculated " + scr.ToString()
    Assert.True(cond,mess)
[<Fact>]
let test_sort_qs() = 
    Psn_tests.setup_pos1() 
    let mvsp = MvsPoss.newtyp(GenCaptures)
    mvsp.State <- DoneHash
    Sort.mvspFinCaps Attack.PlayerWhite Funcs.gm mvsp 0|>ignore    
    let mfrom = mvsp.Mvs.[0].From
    let mto = mvsp.Mvs.[0].To
    let ct = mvsp.Mvs.Count
    let cond=(mfrom=4)&&(mto=36)&&(ct=1)
    let mess="sort captures calculated best as from " + mfrom.ToString() + " to " + mto.ToString() + " count " + ct.ToString()
    Assert.True(cond,mess)
[<Fact>]
let test_sort_main() = 
    Psn_tests.setup_pos1() 
    let mvsp = MvsPoss.newtyp(GenAll)
    mvsp.State <- DoneHash
    Sort.mvspFinAll Attack.PlayerWhite Funcs.gm 1 mvsp 0|>ignore    
    let mfrom = mvsp.Mvs.[0].From
    let mto = mvsp.Mvs.[0].To
    let ct = mvsp.Mvs.Count
    let cond=(mfrom=4)&&(mto=36)&&(ct=1)
    let mess="sort main calculated best as from " + mfrom.ToString() + " to " + mto.ToString() + " count " + ct.ToString()
    Assert.True(cond,mess)

